package com.xmy.cultivate.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

//@Configuration
public class RabbitMqDelayConfig {
    public static final String DELAY_EXCHANGE = "interview.reminder.delay.exchange";
    public static final String DELAY_QUEUE = "interview.reminder.delay.queue";
    public static final String DELAY_ROUTING_KEY = "interview.reminder.delay.key";

    @Bean
    public CustomExchange interviewReminderExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct"); // 设置延迟队列的类型为 direct
        return new CustomExchange(DELAY_EXCHANGE, "x-delayed-message", true, false, args);
    }

    @Bean
    public Queue interviewReminderQueue() {
        return QueueBuilder.durable(DELAY_QUEUE).build();
    }

    @Bean
    public Binding interviewReminderBinding(@Qualifier("interviewReminderQueue") Queue queue,
                                            @Qualifier("interviewReminderExchange") CustomExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(DELAY_ROUTING_KEY).noargs();
    }
}



//@Configuration
//public class RabbitMqDelayConfig {
//    public static final String DELAY_EXCHANGE = "interview.reminder.delay.exchange";
//    public static final String DELAY_QUEUE = "interview.reminder.delay.queue";
//    public static final String DELAY_ROUTING_KEY = "interview.reminder.delay.key";
//
//    @Bean
//    public CustomExchange interviewReminderExchange() {
//        return new CustomExchange(DELAY_EXCHANGE, "x-delayed-message", true, false);
//    }
//    @Bean
//    public Queue interviewReminderQueue() {
//        return QueueBuilder.durable(DELAY_QUEUE).build();
//    }
//    @Bean
//    public Binding interviewReminderBinding(@Qualifier("interviewReminderQueue") Queue queue,
//                                            @Qualifier("interviewReminderExchange") CustomExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange).with(DELAY_ROUTING_KEY).noargs();
//    }
//}
